﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using blackhouse.BlackApart.Data;

namespace blackhouse.BlackApart.Actions.Log {
    public class DaActionLog : IActionLog {

        #region Fields

        private ImpActionLog instance;
        private IActionDataAccess dataAccess;

        #endregion

        #region Properties

        public int LogId {
            get { return this.instance.LogId; }
            private set { this.instance.LogId = value; }
        }

        public DateTime StartDate {
            get { return this.instance.StartDate; }
            set { this.instance.StartDate = value; }
        }

        public DateTime EndDate {
            get { return this.instance.EndDate; }
            set { this.instance.EndDate = value; }
        }

        public ActionStatus Status {
            get { return this.instance.Status; }
            set { this.instance.Status = value; }
        }

        public string Message {
            get { return this.instance.Message; }
            set { this.instance.Message = value; }
        }

        public string Title {
            get { return this.instance.Title; }
            set { this.instance.Title = value; }
        }

        #endregion

        #region Constructors

        public DaActionLog(IActionDataAccess dataAccess) {
            this.dataAccess = dataAccess;
            this.instance = new ImpActionLog();
        }

        #endregion

        #region Methods

        public void Save() {
            this.instance.Save();
            this.dataAccess.SaveLog(this.LogId, this.StartDate, this.EndDate, this.Status.ToString(), this.Title, this.Message);
        }

        public IActionLog AssignNewLogToAction(Action action) {
            DaActionLog log = new DaActionLog(this.dataAccess);
            log.Title = action.GetName();
            action.Log = log;
            return log;
        }

        public void AppendToMessage(string message) {
            this.instance.AppendToMessage(message);
        }

        #endregion

    }
}
